﻿using Flattiverse;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FlattiTroll
{
    public partial class TrollUI : Form
    {
        Connector connector;
        UniverseGroup currentUniverse;

        Thread workerThread;

        List<string> trollMsgs = new List<string>(new string[] { "Wazzup Bro?",
                                                                 "4ll t1ck5 b3l0ng t0 m3",
                                                                 "u mad bros?",
                                                                 "trollin' like it h0000t"});
                                                    

        volatile int tickTroll = 1;

        Random random = new Random();
        

        public TrollUI()
        {
            InitializeComponent();

            connector = new Connector("ddraghici@gmx.de", "6g']u0JA");

            workerThread = new Thread(new ThreadStart(ServerWorker));

            currentUniverse = connector.UniverseGroups["Time Master"];

            currentUniverse.Join("test", currentUniverse.Teams["None"]);

            chatTroller.Start();

            workerThread.Start();

            //Ship ship = currentUniverse.RegisterShip("@Medium", "trollship");

            //ship.Continue();

            //ship.Scan(float.PositiveInfinity, ship.ScannerArea.ExtendedLimit);

            //Console.WriteLine("Hello");

            //ship.Close();

            tbTrollMeter.Maximum = (int)currentUniverse.AvgTickTime.TotalMilliseconds;

            
        }

        public void ServerWorker()
        {
            while (true)
            {
                if (currentUniverse != null)
                {
                    currentUniverse.Commit();
                    currentUniverse.PreWait();
                    currentUniverse.Wait();
                }
                Thread.Sleep(tickTroll);
            }
        }

        private void tbTrollMeter_Scroll(object sender, EventArgs e)
        {
            tickTroll = Math.Max(1, tbTrollMeter.Value);
        }

        private void chatTroller_Tick(object sender, EventArgs e)
        {
            if (currentUniverse != null)
                currentUniverse.Chat(trollMsgs[random.Next(0, trollMsgs.Count - 1)]);

        }
    }
}
